<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // replace 不改变原有的字符

      let str = "hello test me L ";
      // a :me b: 11
      const neWstr = str.replace("me", (a, b) => {
        // 仅仅会替换一个匹配的 因为 函数只是执行一次
        return "nn";
      });
      // 没有g修饰的正则 也是只会替换一次 参数为匹配的字符 以及 index
      const neWstr2 = str.replace(/l/, (a, b) => {
        return "reg";
      });
      //// g修饰的正则  执行次数等于匹配到的个数
      const neWstr3 = str.replace(/l/gi, (a, b) => {
        console.log(a, b);
        return "p";
      });
      console.log(neWstr3);
      var date = "20171129";
      var data = [
        "零",
        "壹",
        "贰",
        "叁",
        "肆",
        "伍",
        "陆",
        "柒",
        "捌",
        "玖",
        "拾",
      ];
      let bb = date.replace(/\d/g, (a) => {
        console.log(a);
        return data[a];
      });
      console.log(bb);
    </script>
  </body>
</html>
